﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using VOL.Core.DBManager;
using VOL.Core.Extensions;
using VOL.Core.ManageUser;
using VOL.Core.Services;
using VOL.Core.Utilities;
using VOL.Entity.DomainModels;
using VOL.MyTable.Repositories;
using syio = System.IO;

namespace VOL.WebApi.Controllers.MyTable.customer_api
{
    [Route("api/customer")]
    [ApiController]
    public class baiduAi : Controller
    {
        // 增值税发票识别
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet, Route("vatInvoice"), AllowAnonymous]
        public async Task<IActionResult> vatInvoice(string fileNamePath)
        {
            WebResponseContent _webResponse = new WebResponseContent();
            if (fileNamePath.IsNullOrEmpty() || fileNamePath == "null")
            {
                _webResponse.Status = false;//默认是false
                return Json(_webResponse.Error("请先上传增值税发票"));
            }
            _webResponse.Data = new { fpstr = (await baiduAi_tools.vatInvoice_async(fileNamePath)).ToString() };
            _webResponse.Status = true;//默认是false
            _webResponse.Message = "OCR成功";
            //= await  baiduAi_tools.vatInvoice_async(fileNamePath);
            //dynamic jo = ((dynamic)_webResponse.Data).fpstr;
            //dynamic jo1=JsonConvert.DeserializeObject(jo).error_code;
            Console.WriteLine(_webResponse.Data);
           return Json(_webResponse);
        }
        // OCR-增值税发票验真
        [HttpPost, Route("invoiceVerification"), AllowAnonymous]
        public static string invoiceVerification()
        {
            return baiduAi_tools.invoiceVerification();
        }
    }
}
